<!-- 加急配置 -->
<template>
    <div >
        <div class='table-page-search-wrapper'>
            <a-form :label-col="{ span: 5 }" :wrapper-col="{ span: 17 }">
                <a-form-item label="免费加急周期">
                    <a-input v-model="freeCycle" placeholder="请输入免费加急周期" suffix="月" allow-clear></a-input>
                </a-form-item>
                <a-form-item label="免费加急次数" >
                    <a-input v-model="freeTimes" suffix="次" placeholder="请输入免费加急次数" allow-clear></a-input>
                </a-form-item>
                <a-form-item label="付费加急金额">
                    <a-input v-model="paymentAmount" suffix="元" placeholder="请输入付费加急金额" allow-clear></a-input>
                </a-form-item>
                <a-form-item label="状态">
                    <a-switch checked-children="开启" un-checked-children="关闭" :checked="status == '1' ? true : false" @change="onChange"/>
                </a-form-item>
                <a-form-item v-bind="formItemLayoutWithOutLabel">
                    <a-button type="primary" @click="submit">确定</a-button>
                </a-form-item>
            </a-form>
        </div>  
    </div>
</template>

<script>
import { queryGoodsUrgentConfig , updateGoodsUrgentConfig } from '@/api/newMall';
export default {
    data () {
        return {
            freeCycle: '', // 免费加急周期（单位：月）
            freeTimes: '', // 免费加急次数
            paymentAmount: '', // 付费加急金额
            status: '1', // 状态
            brandId: this.global.brandId,
            id: '',
            formItemLayoutWithOutLabel: {
                wrapperCol: {
                    xs: { span: 24, offset: 0 },
                    sm: { span: 20, offset: 6 },
                },
            },
        };
    },
    created(){
        this.getData();
    },
    methods: {
        getData(){
            let _this = this;
            const params = {
                page: 0,
                size: 20,
            }
            queryGoodsUrgentConfig(params)
            .then(res => {
                if(res.success){
                    if(res.data.content.length > 0){
                        _this.freeCycle = res.data.content[0].freeCycle;
                        _this.freeTimes = res.data.content[0].freeTimes;
                        _this.paymentAmount = res.data.content[0].paymentAmount;
                        _this.status = res.data.content[0].status;
                        _this.id = res.data.content[0].id;
                    }
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        submit(){
            let _this = this;
            const params = {
                'id': _this.id,
                'freeCycle': _this.freeCycle,
                'freeTimes': _this.freeTimes,
                'paymentAmount': _this.paymentAmount,
                'status': _this.status,
                'brandId': _this.brandId,
            }
            updateGoodsUrgentConfig(params)
            .then(res => {
                if(res.success){
                    _this.$notification['success']({
                        message: '提示',
                        description: '修改成功',
                        duration: 8,
                    })
                    _this.getData();
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        onChange(checked) {
            console.log(`a-switch to ${checked}`);
            this.status = checked ? '1' : '0'
        },
    }
}

</script>
<style scoped>

</style>